import { Button, Card, Checkbox, Form, message, Modal, Radio, Row, Col, Select, Input, InputNumber, Steps, Spin } from "antd";
import { connect } from "dva";
import React, { PureComponent } from "react";
import { transferOption } from "@/utils/common";
import styles from "./index.less";
const FormItem = Form.Item;
const { Step } = Steps;
const operateTypeHash = {
  1: "锁车",
  2: "解除锁车",
  3: "跛行",
  4: "解除跛行"
};


@connect(({ common2, loading, user }) => ({
  common2,
  loading: loading.models.common2,
  currentUser: user.currentUser,
}))
export default class riskLogModal extends PureComponent {
  state = {
    items: [
      {
        key: 1,
        title: '云端：创建配置指令',
        description:'',
        status: 'wait'
      },
      {
        key: 2,
        title: 'Tbox:点火请求配置',
        description:'',
        status: 'wait'
      },
      {
        key: 3,
        title: '云端：下发配置指令', 
        description:'',
        status: 'wait'
      },
      {
        key: 4,
        title: 'Tbox:反馈配置结果', 
        description:'',
        status: 'wait'
      },
    ],
    itemData: {},
    type: '',//操作类型
    description: '',//分析说明
    vin:'',
    loading: false,
  };

  componentDidMount() {
    this.getData();
  }
 
  getData = ()=>{
    const { riskvin } = this.props;
    this.setState({
      loading: true,
    });
    this.props.dispatch({
      type: 'creditCar/postDataWithRes',
      payload: {
        url: '/mscreditbusiness/vehicle/credit/tbox/log', 
        vin: riskvin,
      },
      callback: (res) => {
        if(res.statusCode == '0') {
          this.setState({
            itemData: res.data,
          });
          this.handleData();
        }
        this.setState({
          loading: false,
        });
      },
    })
  }
  handleData = () => {
   const {items, itemData}=this.state;
   const list = Object.assign(items);
   if(itemData.operateTime){
     list.map((item)=>{
      if(item.key === 1){
        item.description = itemData.operateTime,
        item.status = 'finish'
      }
     })
   }
  if(itemData.requestTime){
    list.map((item)=>{
     if(item.key === 2){
       item.description = itemData.requestTime,
       item.status = 'finish'
     }
    })
  }
  if(itemData.responseTime){
    list.map((item)=>{
     if(item.key === 3){
       item.description = itemData.responseTime,
       item.status = 'finish'
     }
    })
  }
  if(itemData.ackTime){
    list.map((item)=>{
     if(item.key === 4){
       item.description = itemData.ackTime,
       item.status = 'finish'
     }
    })
  }
  const newData= list;
  this.setState({
    items: newData,
    type: itemData.operateType,
    description: itemData.description,
  })
  }

  close = () => {
    const { changeriskLogModalVisible } = this.props;
    this.setState({
      items: [
        {
          key: 1,
          title: '云端：创建配置指令',
          description:'',
          status: 'wait'
        },
        {
          key: 2,
          title: 'Tbox:点火请求配置',
          description:'',
          status: 'wait'
        },
        {
          key: 3,
          title: '云端：下发配置指令', 
          description:'',
          status: 'wait'
        },
        {
          key: 4,
          title: 'Tbox:反馈配置结果', 
          description:'',
          status: 'wait'
        },
      ],
      type: '',//操作类型
      description: '',//分析说明
      vin:'',
      loading: false,
    })
    changeriskLogModalVisible(false)
  };

  renderSimpleForm() {
    const { changeriskLogModalVisible } = this.props;
    const { items,type,description} = this.state;
    const footer = (
      <div>
        <Button onClick={this.close}>取消</Button>
      </div>
    );
    return (
      <div>
      <Modal
        footer={footer}
        title="风控日志"
        width={900}
        onCancel={() => changeriskLogModalVisible(false)}
        visible={true}
        style={{ top: 50}}
      >
      <Spin
           spinning={this.state.loading}
           size="large"
        >
        <div style={{ marginLeft: 20 }}>
            <div  style={{ marginBottom: 40 }}>
                <div >操作类型:{operateTypeHash[type]}</div>
            </div>
            <div>
               <div style={{marginBottom: 20 }}>进度跟踪：</div>
               <div className={styles.riskLogModal}>
                <Steps
                 initial={0}
                 labelPlacement="vertical"
                  >
                {items.map((item)=>{//点亮，状态变成finish
                    return <Step  title={item.title} description={item.description} status={item.status}/>
                 })}
                </Steps>
                </div>
            </div>
             <div style={{marginTop: 40 }}>
             <div >分析说明:{description}</div>
             </div>
        </div>
      </Spin>
      </Modal>
      </div>
    );
  }

  render() {
    return this.renderSimpleForm();
  }
}
